import { defineStore } from 'pinia'
import { addComment, detail, getCommentList, remove ,updateComment,removeBatchByCommentsIds} from '@/service/comments/index.js'
import responseMessage from '@/utils/response.js'

const commentStore = defineStore('comment', {
  state: () => ({
    commentList: '',
    detail: ''
  }),
  actions: {
    //获取评论列表
    async getCommentsList(page, size, searchParams) {
    const res = await getCommentList(page, size, searchParams)
    console.log('回传的评论信息结果集是===',res)
    this.commentList = res.data
    console.log('postList结果集是===',this.commentList)
    },
    //新增评论信息
    async addComments(comment) {
      const res = await addComment(comment)
      //responseMessage(res)
      return res
    },
    //修改评论信息
    async updateComments(comment) {
      console.log('修改评论信息',comment)
      const res = await updateComment(comment)
      console.log('修改完了')
      //responseMessage(res)
      return res
    },
    //删除评论  
    async removeCommentById(id) {
      const res = await remove(id)
      responseMessage(res)
    },
    //批量删除评论信息
    async removeBatchByCommentIds(commentsIds) {
      console.log('批量删除评论信息ids',commentsIds)
      const res = await removeBatchByCommentsIds(commentsIds)
      responseMessage(res)
    },
    //评论详情
    async getCommentDetail(id) {
      console.log('准备查询了')
      const res = await detail(id)
      console.log('详情信息是===',res)
      this.detail = res.data.data
      //responseMessage(res)
      return res
    }
  }
})

export default commentStore
